VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmTiposUso 
   Caption         =   "ABM Tipos de Uso"
   ClientHeight    =   4290
   ClientLeft      =   165
   ClientTop       =   735
   ClientWidth     =   7185
   LinkTopic       =   "Form1"
   ScaleHeight     =   4290
   ScaleWidth      =   7185
   StartUpPosition =   2  'CenterScreen
   Begin VB.Frame frameTiposUso 
      Caption         =   "Tipos de Uso"
      Height          =   1335
      Left            =   2520
      TabIndex        =   2
      Top             =   480
      Width           =   4455
      Begin VB.TextBox txtNombre 
         Height          =   375
         Left            =   1560
         MaxLength       =   50
         TabIndex        =   4
         Top             =   720
         Width           =   2415
      End
      Begin VB.TextBox txtId 
         Enabled         =   0   'False
         Height          =   375
         Left            =   1560
         TabIndex        =   3
         Top             =   240
         Width           =   2415
      End
      Begin VB.Label lblNombre 
         Caption         =   "Nombre:"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   6
         Top             =   840
         Width           =   855
      End
      Begin VB.Label lblId 
         Caption         =   "Id:"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   5
         Top             =   360
         Width           =   375
      End
   End
   Begin VB.ListBox lstTiposUso 
      Height          =   3570
      Left            =   0
      TabIndex        =   1
      Top             =   480
      Width           =   2415
   End
   Begin MSComctlLib.Toolbar tbrPrincipal 
      Align           =   1  'Align Top
      Height          =   420
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   7185
      _ExtentX        =   12674
      _ExtentY        =   741
      ButtonWidth     =   609
      ButtonHeight    =   582
      Appearance      =   1
      _Version        =   393216
      BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628} 
         NumButtons      =   7
         BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "sbtAgr"
            Object.ToolTipText     =   "Agregar"
            ImageIndex      =   1
         EndProperty
         BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "sbtMod"
            Object.ToolTipText     =   "Modificar"
            ImageIndex      =   2
         EndProperty
         BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "sbtBus"
            Object.ToolTipText     =   "Buscar"
            ImageIndex      =   3
         EndProperty
         BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "sbtGra"
            Object.ToolTipText     =   "Grabar"
            ImageIndex      =   4
         EndProperty
         BeginProperty Button5 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "sbtCan"
            Object.ToolTipText     =   "Cancelar"
            ImageIndex      =   5
         EndProperty
         BeginProperty Button6 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "sbtBor"
            Object.ToolTipText     =   "Borrar"
            ImageIndex      =   6
         EndProperty
         BeginProperty Button7 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "sbtImp"
            Object.ToolTipText     =   "Imprimir"
            ImageIndex      =   7
         EndProperty
      EndProperty
   End
   Begin VB.Menu mnActividades 
      Caption         =   "Actividades"
      Begin VB.Menu mnAgregar 
         Caption         =   "Agregar"
         Shortcut        =   ^A
      End
      Begin VB.Menu mnModificar 
         Caption         =   "Modificar"
         Shortcut        =   ^M
      End
      Begin VB.Menu mnBuscar 
         Caption         =   "Buscar"
         Shortcut        =   ^B
      End
      Begin VB.Menu mnGrabar 
         Caption         =   "Grabar"
         Shortcut        =   ^G
      End
      Begin VB.Menu mnCancelar 
         Caption         =   "Cancelar"
         Shortcut        =   ^Z
      End
      Begin VB.Menu mnBorrar 
         Caption         =   "Borrar"
         Shortcut        =   ^D
      End
   End
End
Attribute VB_Name = "frmTiposUso"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Estado As Integer

Private Enum Estados
        eEsperarOperacion = 0
        eCargar
        eModificar
        eConsultar ' no se usa
        eBorrar
End Enum

Private Enum TipoDatos
    eString
    eInteger
    eCurrency
    eBoolean
    EDate
End Enum

Private Sub Refrescar_Formulario(Estado As Integer)

    With tbrPrincipal
        .Buttons(3).Visible = False
        .Buttons(7).Visible = False
    End With
            
    Select Case Estado
        Case Estados.eEsperarOperacion
                    
            lstTiposUso.Enabled = True
            
            With frameTiposUso
                .Caption = "Tipos de Uso"
                .Enabled = False
            End With
            
            If lstTiposUso.ListCount = 0 Then
                mnModificar.Enabled = False
                tbrPrincipal.Buttons(2).Enabled = False
            Else
                mnModificar.Enabled = True
                tbrPrincipal.Buttons(2).Enabled = True
            End If
            
            mnAgregar.Enabled = True
            mnGrabar.Enabled = False
            mnCancelar.Enabled = False
            mnBorrar.Enabled = False
                        
            With tbrPrincipal
                .Buttons(1).Enabled = True
                .Buttons(4).Enabled = False
                .Buttons(5).Enabled = False
                .Buttons(6).Enabled = False
                .Buttons(1).ToolTipText = "Nuevo Tipo de Uso"
            End With
            
        Case Estados.eModificar
            With frameTiposUso
                .Caption = " Modificando "
                .Enabled = True
            End With
            
            lstTiposUso.Enabled = False
            
            mnAgregar.Enabled = False
            mnModificar.Enabled = False
            mnGrabar.Enabled = True
            mnCancelar.Enabled = True
            mnBorrar.Enabled = True
            
            With tbrPrincipal
                .Buttons(1).Enabled = False
                .Buttons(2).Enabled = False
                .Buttons(4).Enabled = True
                .Buttons(5).Enabled = True
                .Buttons(6).Enabled = True
            End With

        Case Estados.eCargar
            With frameTiposUso
                .Caption = " Agregando "
                .Enabled = True
            End With
            
            LimpiarTXT Me
             
            lstTiposUso.Enabled = False
            mnAgregar.Enabled = False
            mnModificar.Enabled = False
            
            mnGrabar.Enabled = True
            mnCancelar.Enabled = True
            mnBorrar.Enabled = False
            
            
            With tbrPrincipal
                .Buttons(1).Enabled = False
                .Buttons(2).Enabled = False
                .Buttons(4).Enabled = True
                .Buttons(5).Enabled = True
                .Buttons(6).Enabled = False
            End With
            
        Case Estados.eBorrar
        
            With frameTiposUso
                .Caption = "Tipos de Uso"
                .Enabled = False
            End With

            mnAgregar.Enabled = False
            mnModificar.Enabled = False
            
            mnGrabar.Enabled = True
            mnCancelar.Enabled = True
            mnBorrar.Enabled = False
            
          
            With tbrPrincipal
                .Buttons(1).Enabled = False
                .Buttons(2).Enabled = False
                .Buttons(4).Enabled = True
                .Buttons(5).Enabled = True
                .Buttons(6).Enabled = False
            End With
            
    End Select
    
    Exit Sub
End Sub

Private Sub Form_Load()
Dim oTiposUso As New clsTiposUso
    
    FormsReconfig.Load_Reconfig Me

    oTiposUso.sel_TiposUso
    If (oTiposUso.pCanReg > 0) Then
        CargarLista lstTiposUso, oTiposUso.pRS, 0, 1
    End If
           
    If Not lstTiposUso.ListCount = 0 Then
        cargarTiposUso_by_ID lstTiposUso.ItemData(lstTiposUso.ListIndex)
    End If
    
    Estado = Estados.eEsperarOperacion
    Refrescar_Formulario Estado
        
    Exit Sub
   
End Sub

Private Sub cargarTiposUso_by_ID(ByVal id As Integer)
Dim oRs As New ADODB.Recordset
Dim strSQL As String
Dim i As Integer
Dim oTiposUso As New clsTiposUso
   
    oTiposUso.cargarTiposUso_by_ID id
    
    Set oRs = oTiposUso.pRS
    
    frameTiposUso.Visible = False
   
    LimpiarTXT Me
    
    If Not oRs.EOF Then
        If Not IsNull(oRs("id_tipo_uso")) Then txtId.TEXT = oRs("id_tipo_uso")
        If Not IsNull(oRs("tipo_uso")) Then txtNombre.TEXT = oRs("tipo_uso")
    End If
    
    frameTiposUso.Visible = True
    
    Set oRs = Nothing
    
    Exit Sub

End Sub

Private Sub actualizarTiposUso()
Dim currentIndex As Integer
Dim oTiposUso As New clsTiposUso
Dim strError As String
Dim exito As Boolean
    
        currentIndex = lstTiposUso.ListIndex
        exito = validarDatos(strError)
        If exito Then
            If oTiposUso.ActualizarTiposUso_by_ID(lstTiposUso.ItemData(lstTiposUso.ListIndex), _
                                            txtNombre.TEXT) Then
        
                oTiposUso.sel_TiposUso
                CargarLista lstTiposUso, oTiposUso.pRS, 0, 1
                lstTiposUso.Selected(currentIndex) = True
            
                Estado = Estados.eEsperarOperacion
                Refrescar_Formulario Estado
            Else
                MsgBox "Error al actualizar la informacion del tipo de uso"
            End If
        Else
            MsgBox strError
        End If
End Sub

Private Sub BorrarTiposUso()
Dim oTiposUso As New clsTiposUso

    If oTiposUso.BorrarTiposUso_by_ID(lstTiposUso.ItemData(lstTiposUso.ListIndex)) Then

        oTiposUso.sel_TiposUso
        If (oTiposUso.pCanReg > 0) Then
            CargarLista lstTiposUso, oTiposUso.pRS, 0, 1
        Else
            lstTiposUso.Clear
            LimpiarTXT Me
        End If
        
        Estado = Estados.eEsperarOperacion
        Refrescar_Formulario Estado
    Else
        MsgBox "No se pudo borrar el tipo de uso " & lstTiposUso.ItemData(lstTiposUso.ListIndex)
    End If
        
End Sub

Private Sub grabarTiposUso()
Dim oTiposUso As New clsTiposUso
Dim strError As String
Dim exito As Boolean
        
    exito = validarDatos(strError)
    If exito Then
       If oTiposUso.grabarTiposUso(txtNombre.TEXT) Then
            
            oTiposUso.sel_TiposUso
            If (oTiposUso.pCanReg > 0) Then
                CargarLista lstTiposUso, oTiposUso.pRS, 0, 1
            End If
                    
            Estado = Estados.eEsperarOperacion
            Refrescar_Formulario Estado
    
        Else
            MsgBox "No se pudo crear el nuevo tipo de uso"
        End If
    Else
        MsgBox strError
    End If
End Sub

Private Sub lstTiposUso_Click()
    If lstTiposUso.ListCount > 0 Then
        cargarTiposUso_by_ID lstTiposUso.ItemData(lstTiposUso.ListIndex)
    End If
End Sub

Private Sub mnAgregar_Click()
     Estado = Estados.eCargar
     Refrescar_Formulario Estado
End Sub

Private Sub mnBorrar_Click()
   BorrarTiposUso
End Sub

Private Sub mnCancelar_Click()
    
    If Not lstTiposUso.ListCount = 0 Then
        cargarTiposUso_by_ID lstTiposUso.ItemData(lstTiposUso.ListIndex)
    End If
    
    Estado = Estados.eEsperarOperacion
    Refrescar_Formulario Estado
End Sub

Private Sub mnGrabar_Click()

   Select Case Estado
    Case Estados.eModificar
        actualizarTiposUso
    Case Estados.eCargar
        grabarTiposUso
    End Select

End Sub

Private Sub mnModificar_Click()

    Estado = Estados.eModificar
    Refrescar_Formulario Estado
    
End Sub

Private Sub tbrPrincipal_ButtonClick(ByVal Button As MSComctlLib.Button)
    
    Select Case Button.Key
        Case "sbtAgr"
            mnAgregar_Click
        Case "sbtMod"
            mnModificar_Click
        Case "sbtGra"
            mnGrabar_Click
        Case "sbtCan"
            mnCancelar_Click
        Case "sbtBor"
            mnBorrar_Click
    End Select
    
    Exit Sub

End Sub

Private Function validarDatos(ByRef strError As String) As Boolean
Dim exito As Boolean

    exito = True
    If exito And Trim(Me.txtNombre = "") Then
        exito = False
        strError = "Debe ingresar un nombre de tipo de uso antes de intentar grabar."
        Me.txtNombre.SetFocus
    End If
    If exito And Len(Me.txtNombre) > 50 Then
        exito = False
        strError = "El campo nombre de tipo de uso no debe contener mas de 50 caracteres"
        Me.txtNombre.SetFocus
    End If
    
    validarDatos = exito
End Function


